var _tools = require("../../../utils/tools.js"), _tools2 = _interopRequireDefault(_tools);

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var that, WxParse = require("../../wxParse/wxParse.js"), app = getApp();
let interstitialAd = null;

function exchangeGoods(t) {
    var a = {
        token: wx.getStorageSync("token"),
        id: t.data.id
    };
    _tools2.default.request(a, function(t) {
        2 == t.status ? wx.requestPayment({
            timeStamp: t.info.paydata.timeStamp,
            nonceStr: t.info.paydata.nonceStr,
            package: t.info.paydata.package,
            signType: t.info.paydata.signType,
            paySign: t.info.paydata.paySign,
            success: function(t) {
                wx.showToast({
                    title: "兑换成功"
                }), setTimeout(function() {
                    wx.navigateTo({
                        url: "/bh_bargain/pages/integralOrder/integralOrder"
                    });
                }, 1500);
            },
            fail: function(t) {
                console.log(t);
            }
        }) : 3 == t.status ? wx.showModal({
            title: "提示",
            mask: !0,
            content: t.info,
            showCancel: !1
        }) : (wx.showToast({
            title: "兑换成功"
        }), setTimeout(function() {
            wx.navigateTo({
                url: "/bh_bargain/pages/integralOrder/integralOrder"
            });
        }, 800));
    }, function() {}, function() {}, "", !0, "entry/wxapp/ExchangeGoods");
}

Page({
    data: {
        id: 0,
        indicatorDots: !1,
        vertical: !1,
        autoplay: !0,
        interval: 5e3,
        duration: 1e3,
        isScrollY: !0,
        current: 0,
        isIphoneX: !1,
        isIphone: !1,
        extra_info_tab: 1
    },
    onLoad: function(t) {
        (that = this).data.id = t.id;
    },
    onReady: function() {
        wx.setNavigationBarColor({
            frontColor: "#000000",
            backgroundColor: "#000000"
        }), wx.getSystemInfo({
            success: function(t) {
                if ("ios" == t.platform) {
                    that.setData({
                        isIphone: !0
                    });
                    -1 < t.model.indexOf("iPhone X") && that.setData({
                        isIphoneX: !0
                    });
                }
            }
        }), wx.createSelectorQuery().select("#global-nav").boundingClientRect(function(t) {
            console.log(t.height), that.setData({
                m_height: t.height
            });
        }).exec();
    },
    setAddress: function(t) {
        wx.navigateTo({
            url: "/bh_bargain/pages/address/address"
        });
    },
    onUnload: function() {},
    onHide: function() {},
    swiperchange: function(t) {
        this.setData({
            current: t.detail.current
        });
    },
    switchTab: function(t) {
        this.setData({
            extra_info_tab: t.target.dataset.extra
        });
    },
    onShow: function() {
        var t = {
            action: "details",
            contr: "sign",
            token: wx.getStorageSync("token"),
            id: that.data.id
        };
        _tools2.default.request(t, function(t) {
            that.setData(t.info);
            var a = t.info.goods.introduce;
            WxParse.wxParse("article", "html", a, that, 5);
        });
        if (wx.createInterstitialAd) {
            interstitialAd = wx.createInterstitialAd({
              adUnitId: 'adunit-42e141bfcfdcc315'
            })
            interstitialAd.onLoad(() => {})
            interstitialAd.onError((err) => {})
            interstitialAd.onClose(() => {})
          };
          
          // 在适合的场景显示插屏广告
          if (interstitialAd) {
            interstitialAd.show().catch((err) => {
              console.error(err)
            })
          };
    },
    exchange: function() {
        this.data.address || 1 != that.data.goods.type ? wx.showModal({
            title: "提示",
            content: "确定要兑换该商品",
            success: function(t) {
                t.confirm ? exchangeGoods(that) : t.cancel && console.log("用户点击取消");
            }
        }) : wx.navigateTo({
            url: "/bh_bargain/pages/address/address"
        });
    },
    onShareAppMessage: function() {
        return {
            title: this.data.goods.share_title,
            imageUrl: this.data.goods.cover_image,
            path: "bh_bargain/pages/index/index?parent_id=" + this.data.share.member_id
        };
    }
});